#pragma once
#include "Node.h"

template<typename T>
class Chain
{
public:
	Chain();

	Node<T>* get_root();
	Node<T>* new_node(T data);

	void add(Node<T>*, int);
	void add(Node<T>*);

	void del();

	int len();
private:
	Node<T> * root;
};

template<typename T>
inline Chain<T>::Chain()
{
	root = nullptr;
}

template<typename T>
inline Node<T> * Chain<T>::get_root()
{
	return root;
}

template<typename T>
inline Node<T>* Chain<T>::new_node(T data)
{
	return new Node<T>(data);
}

template<typename T>
inline void Chain<T>::add(Node<T> * node, int index)
{
	Node<T>* now = get_root();
	int i = 0;
	while (i++ <= index) {
		if (now == nullptr)
		{
			break;
		}
		now = now->next;
	}
	now = node;
}

template<typename T>
inline void Chain<T>::add(Node<T> * node)
{
	Node<T>* now = get_root();
	if (now == nullptr) {
		root = node;
		return;
	}
	while (now->next != nullptr)
		now->next = node;
}

template<typename T>
inline void Chain<T>::del()
{
	//TODO
}

template<typename T>
inline int Chain<T>::len()
{
	int i = 0;
	Node<T> * now = get_root();
	while (now != nullptr)
	{
		i++; now = now->next;
	}
	return i;
}




class IntChain:
	public Chain<int>
{
};
